package 贫困等级;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MapTest extends Mapper<LongWritable, Text,Text, JavaBean> {
    Text k = new Text();
    JavaBean v = new JavaBean();
    SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy/MM/dd");
    SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy年MM月dd日");
    String time = null;
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String [] datas = value.toString().split("\t",-1);
        for (String data:datas){
            if (data==null||"".equals(data))return;
        }
        try {
            Date date = simpleDateFormat1.parse(datas[7]);
            time = simpleDateFormat2.format(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        k.set(datas[0]);
        v.set(datas[0],datas[1],datas[2],datas[3],datas[4],datas[5],datas[6],time,Double.parseDouble(datas[8]));
        context.write(k,v);
    }
}
